import 'package:flutter/material.dart';

import '../../dao/follow_dao.dart';
import '../../models/follow/follow_model.dart';
import 'follow_item_widget.dart';

class FollowPage extends StatefulWidget {
  const FollowPage({super.key});

  @override
  State<FollowPage> createState() => _FollowPageState();
}

class _FollowPageState extends State<FollowPage> {
  late Future<List<FollowModel>> _followModels;

  @override
  void initState() {
    _followModels = FollowDao.fetchAllContact(0);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("新增关注"),
      ),
      body: FutureBuilder(
        future: _followModels,
        builder:
            (BuildContext context, AsyncSnapshot<List<FollowModel>> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting ||
              snapshot.connectionState == ConnectionState.done &&
                  snapshot.data == null) {
            return const Center(
              child: Text("loading....."),
            );
          }

          return ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              return Container(
                margin: EdgeInsets.all(10),
                child: FollowItemWidget(followModel: snapshot.data![index]),
              );
            },
            itemCount: snapshot.data?.length,
          );
        },
      ),
    );
  }
}
